#include "PictureBox.h"
#include "Shape.h"

#include "..\Graphic\HgeGraphic.h"

#include <iostream>
using namespace std;

namespace air {
	PictureBox::PictureBox(Shape* _shape,float _x,float _y,int _picID)
		:shape(_shape->duplicate()), lastMouseInPictureBox(false),
		x(_x),y(_y),picID(_picID)
	{
	}

	PictureBoxHgeObject::~PictureBoxHgeObject() {
	}
	
	PictureBox::~PictureBox() {
		delete shape;
	}

	bool PictureBox::isPointInObject(float x, float y) {
		return shape->isPointInShape(x, y);
	}


	DWORD PictureBox::getColor() const {
		return color;
	}

	void PictureBox::setColor(DWORD _color) {
		color = _color;
	}

	Shape* PictureBox::getShape() {
		return shape;
	}

	float PictureBox::getX() const{
		return x;
	}
	float PictureBox::getY() const{
		return y;
	}

	int PictureBox::getPicID() const{
		return picID;
	}

	void PictureBox::setPicID(int _picID) {
		picID = _picID;
	}


	PictureBoxHgeObject::PictureBoxHgeObject(PictureBox* PictureBox): picObj(PictureBox) 
	{
		picID = picObj->getPicID();
		x = picObj->getX();
		y = picObj->getY();
		if (picObj->getShape()->getType() == SHP_RECT) {
			Rect* rect = (Rect*)picObj->getShape();
		}
	}

	bool PictureBoxHgeObject::initialize(Graphic* _g) {
		HgeGraphic* hg = (HgeGraphic*) _g;
		tex[0] = hg->getTexture("background2");
		tex[1] = hg->getTexture("start");
		tex[2] = hg->getTexture("start2");
		tex[3] = hg->getTexture("return");
		tex[4] = hg->getTexture("return2");
		tex[5] = hg->getTexture("start");
		tex[6] = hg->getTexture("start2");
		tex[7] = hg->getTexture("join1");
		tex[8] = hg->getTexture("join2");
		tex[9] = hg->getTexture("option1");
		tex[10] = hg->getTexture("option2");
		tex[11] = hg->getTexture("exit1");
		tex[12] = hg->getTexture("exit2");
		tex[13] = hg->getTexture("room");
		tex[14] = hg->getTexture("background1");
		spr = new hgeSprite(tex[picID], 0.0f, 0.0f, x, y);
		spr->SetColor(0xffffffff);
		return true;
	}

	void PictureBoxHgeObject::render() {
		if (picObj->getShape()->getType() == SHP_RECT) {
			Rect* rect = (Rect*)picObj->getShape();
			spr->SetTexture(tex[picObj->getPicID()]);
			spr->SetColor(picObj->getColor());
			spr->Render(rect->getPositionX(), rect->getPositionY());
		}
	}
}
